home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************************
- *
- * PROGRAM NAME: PLAYMIDI.C
- *
- * COMPILER: Borland/Turbo C/C++
- *
- * DESCRIPTION: Plays a .MID MIDI file from the disk using the SBMIDI
- * driver (accessed from SBSIM). To run the program,
- * type the following at the command line:
- *
- * PLAYMIDI FILENAME
- *
- * Where FILENAME is the drive/path/filename of the .MID
- * file to play.
- *
- * NOTE: SBSIM driver must be loaded before running this program.
- *
- *********************************************************************/
- #define MIDI_DRIVER 0x10
-
- #include <fcntl.h>
- #include <ctype.h>
- #include <conio.h>
- #include <io.h>
- #include <stdio.h>
- #include "drvrfunc.c"
- #include "drvrfunc.h"
-
-
- /********************************************************************/
- void main(int argc, char **argv)
- {
- char Command,
- UserQuit;
-
- int FileHandle;
- SIMERR RetValue;
-
- if (argc != 2) // argc = no. of parameters entered on command line
- {
- puts("Command line must contain EXACTLY ONE filename parameter!");
- return; // Terminate program
- }
-
-
- /*--- SEE IF SBSIM DRIVER HAS LOADED --*/
- SIMint = FindDvr("SBSIM", 0x0103); // Get SBSIM's interrupt no.
- if (SIMint == 0)
- {
- puts("SBSIM driver not loaded!");
- return; // Terminate program
- }
-
- /*--- SEE IF MIDI DRIVER HAS LOADED ---*/
- if (!(GetDrvrs() & MIDI_DRIVER))
- {
- puts("SBMIDI not loaded!");
- return; // Terminate program
- }
-
-
- /*--- LOAD THE FILE -------------------*/
- if ((FileHandle = _open(argv[1], O_BINARY | O_RDONLY)) == -1)
- {
- printf("FILE: %s not successfully opened!\n", argv[1]);
- return; // Terminate program
- }
-
-
- /*--- StartSnd() LOADS THE FILE AND INITIALIZES THE SBMIDI DRIVER ---*/
- RetValue = StartSnd(Midi, (void far *) argv[1], NULL, NULL);
- if (RetValue != SIMerr_NoErr)
- {
- printf("ERROR CALLING SBSIM: %s\n", errorMsg[RetValue]);
- _close(FileHandle);
- return; // Terminate program
- }
-
- /*--- PlaySnd() BEGINS PLAYING THE FILE -------------*/
- RetValue = PlaySnd(Midi);
- if (RetValue != SIMerr_NoErr)
- {
- printf("ERROR CALLING SBSIM: %s\n", errorMsg[RetValue]);
- _close(FileHandle);
- return; // Terminate program
- }
-
- clrscr(); // Clear screen
- printf("\n\n\n\n\n SELECT ONE OF THE FOLLOWING OR WAIT UNTIL DONE:\n\n");
- printf(" (P)ause\n");
- printf(" (R)esume\n");
- printf(" (Q)uit\n");
-
- UserQuit = FALSE;
-
- /*--- PROCESS USER INTERACTION OR WAIT FOR SOUND TO STOP -----------*/
- do
- {
- if (kbhit()) // Was a key pressed?
- {
- Command = toupper(getch()); // Get char that's in buffer
- if (Command == 'P')
- PauseSnd(Midi);
- else if (Command == 'R')
- ResumeSnd(Midi);
- else if (Command == 'Q')
- UserQuit = TRUE;
- }
- // Exit do-while loop if file is done playing or user typed 'Q'
- } while (GetSndStat(Midi) != 0 && UserQuit == FALSE);
-
-
- /*--- IF SOUND IS STILL PLAYING AND USER HIT 'Q', STOP THE SOUND ---*/
- if (GetSndStat(Midi) != 0 && UserQuit == TRUE)
- StopSnd(Midi);
-
- return;
- }